package com.kehutong.work.order.manage.service;

import org.coraframework.inject.Inject;
import org.coraframework.mvc.webservice.WebService;
import org.coraframework.orm.Pool;
import org.coraframework.orm.jdbc.JdbcSession;
import org.coraframework.util.Objects;

import com.kehutong.common.errcode.Result;
import com.kehutong.work.order.manage.entity.WorkOrderManageSetting;

@WebService("/work/order/manage/setting/service")
public class WorkOrderSettingService {

    @Inject
    private JdbcSession jdbcSession;

    public Object setting(WorkOrderManageSetting setting) {
        if (Objects.isNull(setting)) {
            setting = Pool.newInstance(WorkOrderManageSetting.class, "1000");
            setting.setMode(1);
            jdbcSession.insert(setting);
            return Result.success();
        }

        jdbcSession.updateById(setting);
        return Result.success();
    }

    public WorkOrderManageSetting getSetting(){
        WorkOrderManageSetting setting = Pool.get(WorkOrderManageSetting.class, "1000");
        if (Objects.isNull(setting)) {
            setting = Pool.newInstance(WorkOrderManageSetting.class, "1000");
            setting.setMode(1);
            jdbcSession.insert(setting);
        }
        return setting;
    }
}
